﻿CREATE PROCEDURE [dbo].[Security_LoginUser]
-- --------------------------------------------------------------------------------- 
-- Procedure Name:  Security_LoginUser
--
-- Description: Authenticates a user and returns the result
--
--
--
-- Version  Date          Author           Description
-- ---------------------------------------------------------------------------------
--  1       30-Oct-2011   The Collective   Created procedure
--
--
--
-- ---------------------------------------------------------------------------------
-- ---------------------------------------------------------------------------------
(@username varchar(255),
 @passwordencrypt varchar(255),	  
 @validated bit output)
AS
BEGIN
	
	SET NOCOUNT ON;
	

	-- Validate the credentials
	SELECT @validated = 1 
	FROM Accounts_User 
	WHERE account_disabled = 0 
	and username=@username 
	and passwordencrypt=@passwordencrypt;
		
	-- Update the last login date for the user
	if (@validated = 1)
	BEGIN
	   Update Accounts_User set account_lastlogindate=getdate()  Where username = @username;
	END;
	ELSE
	BEGIN
	   -- Ensure output parameters are never null
	   Set @validated = 0;	   
	END;
		  
END;